<template>
  <div class="login">
    <h1>登陆</h1>
    <div class="login-wrapper">
      <el-form :model="ruleForm" label-width="100px">
        <el-form-item label="手机" prop="phone">
          <el-input type="text" v-model="ruleForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称" prop="nickname">
          <el-input type="text" v-model="ruleForm.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
      </el-form>
      {{str}}
    </div>
  </div>
</template>

<script>
import { getLogin } from "@/api/api";
import { mapActions, mapState } from "vuex";
export default {
  data() {
    return {
      ruleForm: {
        phone: "",
        pass: "",
        nickname: ""
      }
    };
  },
  watch: {
    str(val) {
      console.log(val, "val");
    }
  },
  computed: {
    ...mapState(["str"])
    // str: this.store.state.str
  },
  methods: {
    ...mapActions(["updateToken"]),
    submitForm() {
      this.$store.commit("UPDATE_TOKEN", "jiangyuxin");
      // getLogin({
      //   phone: this.ruleForm.phone,
      //   pass: this.ruleForm.pass,
      //   nickname: this.ruleForm.nickname
      // }).then(res => {
      //   console.log(res, "res"); // code = 0
      //   if (res && res.msg === "登陆成功") {
      //     // sessionStorage.setItem('token', res.token)
      //     // this.updateToken(res.token);
      //     this.$store.commit("UPDATE_TOKEN", "jiangyuxin");
      //     this.$router.push("/homeIndex/table");
      //   }
      // });
    }
  }
};
</script>

<style lang="scss">
.login-wrapper {
  width: 400px;
  height: 500px;
  margin: 0 auto;
}
</style>